package com.sale.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.sale.common.core.domain.R;
import com.sale.common.core.web.controller.BaseController;
import com.sale.common.mybatis.core.page.PageQuery;
import com.sale.common.mybatis.core.page.TableDataInfo;
import com.sale.system.domain.SysCategory;
import com.sale.system.domain.SysMaterialCoding;
import com.sale.system.domain.dto.SysMaterialCodingDto;
import com.sale.system.domain.dto.SysTheDropDto;
import com.sale.system.domain.vo.SysMaterialCodingVo;
import com.sale.system.service.ISysMaterialCodingService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @Author: YSL
 * @Date: 2023-07-10 09:24:21
 * @Desc: 物料类别表Controller
 */
@RestController
@RequestMapping("/SysMaterialCoding")
@Validated
@RequiredArgsConstructor
public class SysMaterialCodingController extends BaseController {

    /**
     * 物料类别表Service
     */
    private final ISysMaterialCodingService SysMaterialCodingService;

    /**
     * 获取物料类别列表
     */
    //@SaCheckPermission("system:materielType:list")
    @GetMapping("/list")
    public TableDataInfo<SysMaterialCodingDto> list(SysMaterialCodingVo sysMaterialCodingVo, PageQuery pageQuery) {
        return SysMaterialCodingService.selectSysMaterialCodingList(sysMaterialCodingVo, pageQuery);
    }

    /**
     * 查询单个物料类别
     */
    //@SaCheckPermission("system:materielType:query")
    @GetMapping(value = "/{codingId}")
    public R<SysMaterialCoding> getSysMaterialCodingById(@PathVariable Long codingId) {
        return R.ok(SysMaterialCodingService.getSysMaterialCodingById(codingId));
    }

    /**
     * 新增物料类别
     */
    //@SaCheckPermission("system:materielType:add")
    @PostMapping
    public R<Void> add(@RequestBody SysMaterialCodingVo sysMaterialCodingVo) throws Exception {
        return toAjax(SysMaterialCodingService.insertMaterialCoding(sysMaterialCodingVo));
    }

    /**
     * 修改物料类别
     */
    //@SaCheckPermission("system:materielType:edit")
    @PutMapping
    public R<Void> edit(@RequestBody SysMaterialCodingVo sysMaterialCodingVo) throws Exception {
        return toAjax(SysMaterialCodingService.updateMaterialCoding(sysMaterialCodingVo));
    }

    /**
     * 删除物料类别
     */
    //@SaCheckPermission("system:materielType:remove")
    @DeleteMapping(value = "/{codingId}")
    public R<Void> remove(@PathVariable Long codingId) throws Exception {
        return toAjax(SysMaterialCodingService.deleteMaterialCoding(codingId));
    }

    /**
     * 获取物料类别下拉
     */
    @GetMapping("/selectDropdown")
    public R<List<SysTheDropDto>> selectDropdown(SysMaterialCodingVo sysMaterialCodingVo) {
        return R.ok(SysMaterialCodingService.selectDropdown(sysMaterialCodingVo));
    }

    /**
     * 获取全部物料类别下拉
     */
    @GetMapping("/selectAllDropdown")
    public R<List<SysTheDropDto>> selectAllDropdown() {
        return R.ok(SysMaterialCodingService.selectAllDropdown());
    }


    /**
     * 根据物料编码获取对应类别信息（dubbo 调用）
     */
    @GetMapping("/getByCode")
    public R<SysCategory> getByCode(String materialCode) {
        return R.ok(SysMaterialCodingService.getByCode(materialCode));
    }
}
